import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getParameter")
public class GetParameter  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        if(username == null){
            System.out.println("username 这个 key 在 body 中不存在");
        }

        if (password == null){
            System.out.println("password 这个 key 在 body 中不存在");

        }

        System.out.println("username = " + username + "  " + "password = " + password);
        resp.getWriter().write("ok");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf8");

        String username = req.getParameter("username");
        String password = req.getParameter("password");

        if(username == null){
            System.out.println("username2 这个 key 在 body 中不存在");
        }

        if (password == null){
            System.out.println("password2 这个 key 在 body 中不存在");

        }

        System.out.println("username = " + username + "  " + "password = " + password);
        resp.getWriter().write("ok");
    }
}
